document.getElementById('searchBtn').onclick = function() {
    const selectedTags = Array.from(document.querySelectorAll('input[type="checkbox"]:checked'))
        .map(checkbox => parseInt(checkbox.value.replace('tag', ''))); // 假设标签值为tag1, tag2等

    fetch('/webapi/patient/recommend', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(selectedTags)
    })
        .then(response => response.json())
        .then(data => {
            // 处理推荐结果
            console.log(data);

            // 更新推荐科室
            const departmentContainer = document.getElementById('departmentContainer'); // 获取科室显示区域
            departmentContainer.innerHTML = ''; // 清空当前内容
            data.departments.forEach(department => {
                const departmentDiv = document.createElement('div');
                departmentDiv.className = 'border-bottom p-2';
                departmentDiv.textContent = department.name; // 显示科室名称
                departmentContainer.appendChild(departmentDiv);
            });

            // 更新推荐医院
            const hospitalContainer = document.getElementById('hospitalContainer'); // 获取医院显示区域
            hospitalContainer.innerHTML = ''; // 清空当前内容
            data.hospitals.forEach(hospital => {
                const hospitalDiv = document.createElement('div');
                hospitalDiv.className = 'border-bottom p-2';
                hospitalDiv.textContent = `${hospital.name} (评分: ${hospital.score}) - 地址: ${hospital.address}`; // 显示医院名称、评分和地址
                hospitalContainer.appendChild(hospitalDiv);
            });

            // 显示推荐结果区域
            document.getElementById('resultContainer').classList.remove('d-none');
        })
        .catch(error => {
            console.error('Error fetching recommendations:', error);
        });
};
